module.exports = function ($scope, $resource, $modal, $modalInstance, travel, getDate, toaster, updateFlag, checkFlag){

    $scope.updateFlag = updateFlag;
    $scope.checkFlag = checkFlag;
    $resource('/api/as/goc/travelinfo/getTravelInfoList', {}, {}).save({'sale_code': travel.sale_code}, function(res){
        if (res.errcode === 0) {
            $scope.travelInfoList = res.data;
        } else {
            toaster.error({title: '', body: '查询游客信息失败'});
        }
    });

    $scope.update = function(obj){
        var modalInstance = $modal.open({
            template: require('../views/saleSignUp.html'),
            controller: 'saleSignUp',
            size: 'lg',
            resolve: {
                getDate : function(utilservice){
					return utilservice.getDate;
				},
                travel: function () {
                    return travel;
                },
                people: function () {
                    return obj;
                }
            }
        });
        modalInstance.result.then(function(result){
            obj.name = result.name;
            obj.sex = result.sex;
            obj.mobile = result.mobile;
            obj.email = result.email;
            obj.remark = result.remark;
        });
    }

    $scope.delete = function(obj, index){
        if(confirm('删除后将取消此人报名的信息，无法继续跟随游团。')){
            var para = {
                'sale_code': obj.sale_code,
                'cardno': obj.cardno
            }
            $resource('/api/ac/goc/travelInfoService/deleteTravelInfo', {}, {}).save(para, function(res){
                if (res.errcode === 0) {
                    toaster.success({title: '', body: '取消报名成功'});
                    $scope.travelInfoList.splice(index, 1);
                } else {
                    toaster.error({title: '', body: res.errmsg});
                }
            });
        }
    }

    $scope.setSaleStatus = function (status){
        var para = {
            'group_code': travel.group_code,
            'sale_code': travel.sale_code,
            'status': status
        }
        $resource('/api/ac/goc/outboundTravelService/setSaleStatus', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '成功'});
                $modalInstance.close(status);
            } else {
                toaster.error({title: '', body: '审核失败'});
            }
        });
    }

    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }

};